import queue
import threading


class ThreadPoolManager():
    def __init__(self, thread_num):
        self.workQueue = queue.Queue()
        for i in range(thread_num):
            thead = WorkQueue(self.workQueue)
            thead.start()

    def add_work_queue(self, func, *args):
        self.workQueue.put((func, args))


class WorkQueue(threading.Thread):
    def __init__(self, work_queue):
        super().__init__()
        self.workQueue = work_queue
        self.daemon = True

    def run(self):
        while True:
            func, args = self.workQueue.get()
            # print('threading.current_thread().getName() %s', threading.current_thread().getName())
            func(*args)
            self.workQueue.task_done()
